import { createApp } from 'vue'
import Toast from '~/components/Toast.vue'

export default defineNuxtPlugin(() => {
  // 创建toast实例
  const toastApp = createApp(Toast)
  const toastContainer = document.createElement('div')
  document.body.appendChild(toastContainer)
  const toastInstance = toastApp.mount(toastContainer)

  // 提供全局toast方法
  return {
    provide: {
      toast: {
        success: (message, duration = 3000) => toastInstance.show(message, 'success', duration),
        error: (message, duration = 3000) => toastInstance.show(message, 'error', duration),
        warning: (message, duration = 3000) => toastInstance.show(message, 'warning', duration),
        info: (message, duration = 3000) => toastInstance.show(message, 'info', duration)
      }
    }
  }
}) 